const App = getApp()

Page({
  data: {
    imgUrls: [
      'https://file.sunf.top/files/00/175866434296.jpg',
      'https://file.sunf.top/files/00/a014.jpg',
      'https://file.sunf.top/files/00/a02.JPG'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    circular: true,
    articleList: [],
    imglist: [],
    dditem: {
      index: 0,
      msg: 'this is a template',
      time: '2016-09-15'
    }
    
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  //预览图片 
  previewImage: function (e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: this.data.imglist // 需要预览的图片http链接列表  
    })
  },
  //分享
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '铂爵影楼实景装修设计',
      path: 'pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options ) {
    var that = this;
    //获取数据  
    wx.request({
      url: getApp().globalData.baseURL + '/commWxApp/index/api', //仅为示例，并非真实的接口地址
      data: {
        pageSize: getApp().globalData.pageSize,
        pageNo: '1',
        siteCode:'www'
      },
      header: {
        'content-type': 'application/json', // 默认值
      },
      success: function (res) {
        const result = res.data
        console.log(result)
        if (result.result == true){
          var list = result.data.list;
          //console.log(result.data.list)
          //载入数据
          that.setData({
            articleList: list
          })
          //将数据加入图片查看集合
          var imgs = [];
          for (var i = 0; i < list.length; ++i) {
            if (list[i].picture){
              imgs.push(list[i].picture);
            }
          }
          that.setData({
            imglist: imgs
          })
         
        }

      }
    }) 

  }
})



